package com.online.teaching.module.common.resource.service.impl;

import com.online.teaching.dao.FileMapper;
import com.online.teaching.module.common.resource.domain.vo.GetDirectoryVO;
import com.online.teaching.module.common.resource.domain.vo.GetFileVO;
import com.online.teaching.module.common.resource.service.CommonResourceService;
import com.online.teaching.module.common.resource.utils.MenuTreeUtil;
import com.online.teaching.pojo.File;
import com.online.teaching.utils.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName : CommonResourceServiceImpl  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-26 18:36  //时间
 */
@Service
public class CommonResourceServiceImpl implements CommonResourceService {

    @Autowired
    private FileMapper fileMapper;

    @Override
    public List<Object> getDirectoryTree(Integer teachesId) {
        List<File> files = fileMapper.selectFileByTeachesId(teachesId);
        List<GetDirectoryVO> getDirectoryVOS = SmartBeanUtil.copyList(files, GetDirectoryVO.class);
        MenuTreeUtil menuTreeUtil=new MenuTreeUtil();
        List<Object> objects = menuTreeUtil.menuList(getDirectoryVOS);
        return objects;
    }

    @Override
    public List<GetFileVO> getFileList(Integer directoryId) {
        File file = fileMapper.selectByPrimaryKey(directoryId);
        if(file==null){
            return null;
        }
        List<File> files = fileMapper.selectFileListByParent(directoryId);
        List<GetFileVO> getFileVOS = SmartBeanUtil.copyList(files, GetFileVO.class);
        return getFileVOS;
    }
}
